#include "gxde.h"
#include "qrcutil.h"

#include <httpclient.h>

/**
 * @brief GXDE::GXDE
 * https://github.com/orgs/GXDE-OS/repos_list?q=&page=1
 * for i in $(seq `curl -G  'https://github.com/orgs/GXDE-OS/repos_list?q=&page=1'   -H 'accept: application/json'   | jq .pageCount`); do echo $i; done
 * for i in $(seq `curl -G  'https://github.com/orgs/GXDE-OS/repos_list?q=&page=1'   -H 'accept: application/json'   | jq .pageCount`); do curl -G  "https://github.com/orgs/GXDE-OS/repos_list?q=&page=$i"   -H 'accept: application/json'; done | jq -s | jq .repositories | jq -s add
 */
GXDE::GXDE() {

}

QString GXDE::name()
{
    return "GXDE-OS";
}

QString GXDE::prefix()
{
    return "https://github.com/GXDE-OS/";
}

QList<QListWidgetItem *> GXDE::searching_item(const QString &text)
{
    QList<QListWidgetItem *> list;
    foreach (auto item, Response(0, QR("://gxde.json")).toList()) {
        auto repo = item.toMap();
        auto name = repo.value("name").toString();
        if (text.isEmpty() || name.contains(text, Qt::CaseInsensitive)) {
            auto v = newItem();;
            v->setText(name);
            list << v;
        }
    }
    return list;
}

QString GXDE::content_item(const QListWidgetItem *item)
{
    return prefix() + item->text();
}
